$(document).ready(function () {

    //Language div's opening and closing codes.
    $(".languageMainLink").click(function (e) {
        if ($(".languageBoxMenuDiv").is(':hidden')) {
            $(".languageBoxMenuDiv").slideDown(200);
        }
        else {
            $(".languageBoxMenuDiv").slideUp(200);
        }
        $('body').one('click', function () {
            $(".languageBoxMenuDiv").slideUp(200);
        });
        e.stopPropagation();
    });
    //Language div's opening and closing codes.---END

    //Writing the selected language to language div header.
    $(".languageBoxMenuDiv div").click(function () {
        var spanValue = $(this).children("span").text()
        $("img.languageFlag").attr('src', $(this).children("img").attr('src'));
        $("span.languageSpan").text(spanValue);
    });
    //Writing the selected language to language div header.---END


    //MENU Hover and adjustments
    $(".menuMainHeader").hover(
	  function () {
	      $(this).prev("li").children("a").addClass("noBg");
	      $(this).children(".menuContent").show();
	      $(this).children(".menuMainHeaderLink").addClass("menuMainHeaderLinkHover");
	  },
	  function () {
	      $(this).prev("li").children("a").removeClass("noBg")
	      $(this).children(".menuContent").hide();
	      $(this).children(".menuMainHeaderLink").removeClass("menuMainHeaderLinkHover");
	  }
	);

    $(".menuFirstHeader a").hover(function () {
        $(this).children('img').attr("src", "/content/themes/default/img/menu/menuHomeHover.png");
    },
	  function () {
	      $(this).children('img').attr("src", "/content/themes/default/img/menu/menuHome.png");
	  }
	);
    $('.menuInnerContent').hide(); // Hide all divs
    $('.1_menuInnerContent').show(); // Show the first div
    $('.1_menuheader').addClass('menuInnerHeadersActive'); // Set the class for active state
    $('.menuInnerHeaders ul li a').hover(function () { // When link is clicked
        $(this).parents(".menuInnerHeaders").find("a").removeClass('menuInnerHeadersActive'); // Remove active class from links
        $(this).addClass('menuInnerHeadersActive'); //Set parent of clicked link class to active

        var currentTab = $(this).attr("class"); // Set currentTab to value of href attribute
        currentTab = currentTab.substring(0, currentTab.indexOf("_"));
        $(this).parents(".menuInnerHeaders").siblings('.menuInnerContent').hide(); // Hide all divs
        $(this).parents(".menuInnerHeaders").siblings("." + currentTab + "_menuInnerContent").show(); // Show div with id equal to variable currentTab
    });

    $('.menuInnerContent2').hide(); // Hide all divs
    $('.1_menuInnerContent2').show(); // Show the first div
    $('.1_menuheader2').addClass('menuInnerHeadersActive'); // Set the class for active state
    $('.menuInnerHeaders2 ul li a').hover(function () { // When link is clicked
        $(this).parents(".menuInnerHeaders2").find("a").removeClass('menuInnerHeadersActive'); // Remove active class from links
        $(this).addClass('menuInnerHeadersActive'); //Set parent of clicked link class to active


        var currentTab = $(this).attr("class"); // Set currentTab to value of href attribute
        currentTab = currentTab.substring(0, currentTab.indexOf("_"));
        $(this).parents(".menuInnerHeaders2").siblings('.menuInnerContent2').hide(); // Hide all divs
        $(this).parents(".menuInnerHeaders2").siblings("." + currentTab + "_menuInnerContent2").show(); // Show div with id equal to variable currentTab
    });
    //MENU Hover and adjustments ---END

    //Home Content Tabs
    $('.homeContentTabDiv').hide(); // Hide all divs
    $('.homeContentTabContents .homeContentTabDiv:first').show(); // Show the first div
    $('.homeContentTabHeaders li:first a').addClass('selected '); // Set the class for active state
    $('.homeContentTabHeaders li a').click(function () { // When link is clicked
        $('.homeContentTabHeaders li a').removeClass('selected '); // Remove active class from links
        $(this).addClass('selected '); //Set parent of clicked link class to active

        var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
        $('.homeContentTabDiv').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });

    /* selected tab assigment */
    var selectedTab = window.location.hash.replace("#", "");
    if (selectedTab != '' && selectedTab != null && selectedTab != '#') {
        $('.homeContentTabDiv').hide(); // Hide all divs
        $('.homeContentTabHeaders li:first a').addClass('selected ');
        $('.homeContentTabHeaders li a').removeClass('selected ');
        $("#" + selectedTab).show(); // Show div with id equal to variable currentTab
        $('a[href$="#' + selectedTab + '"]').addClass('selected');
    }
    //Home Content Tabs END

    //Home livePrices Tabs
    $('.livePricesTab').hide(); // Hide all divs
    $('.livePricesTab:first').show(); // Show the first div
    $('.homeContentLivePricesTabHeaderDiv li:first a').addClass('selectedLivePricesLi'); // Set the class for active state
    $('.homeContentLivePricesTabHeaderDiv li a').click(function () { // When link is clicked
        $('.homeContentLivePricesTabHeaderDiv li a').removeClass('selectedLivePricesLi'); // Remove active class from links
        $(this).addClass('selectedLivePricesLi'); //Set parent of clicked link class to active

        var currentTab = $(this).attr('href'); // Set currentTab to value of href attribute
        $('.livePricesTab').hide(); // Hide all divs
        $(currentTab).show(); // Show div with id equal to variable currentTab
        return false;
    });
    //Home livePrices Tabs END


    //Layerslider adj
    $('.homeBanner').layerSlider({
        skin: 'lightskin',
        skinsPath: '../layerslider/skins/'

    });
    //Layerslider adj




    $(".loginMyGkfxBackgroundDiv").css("opacity", "0");
    $(".loginToMyGkfxButton").click(function () {
        $(".loginMyGkfxBackgroundDiv").slideDown(100);
        $(".loginMyGkfxBackgroundDiv").animate({ opacity: 1 }, 200, function () { });
        $(this).addClass("loginToMyGkfxButtonHover");
    });
    $(".loginMyGkfxClose").click(function () {
        $(".loginMyGkfxBackgroundDiv").animate({ opacity: 0 }, 100, function () { });
        $(".loginMyGkfxBackgroundDiv").slideUp(200);
        $(".loginToMyGkfxButton").removeClass("loginToMyGkfxButtonHover");
        $(".forgotPassword").fadeOut(200);
        $(".loginMyGkfx").fadeIn(200);

    });

    $(".loginMyGkfxForgotDetails").click(function () {
        $(".loginMyGkfx").fadeOut(200);
        $(".forgotPassword").fadeIn(200);
    });
    $(".tryToLoginAgainButton").click(function () {
        $(".forgotPassword").fadeOut(200);
        $(".loginMyGkfx").fadeIn(200);
    });


    $(".liveChatButton").fancybox({
        'width': '65',
        'height': '47',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe',
        'padding': '0',
        'titleShow': false,
        'overlayShow': true

    });
    //<![CDATA[
    $(".default-usage-select").selectbox().bind('change', function () {
        $('<div>Value of #default-usage-select changed to: ' + $(this).val() + '</div>').appendTo('#demo-default-usage .demoTarget').fadeOut(5000, function () {
            $(this).remove();
        });
    });
    //]]>
    $(".multiSelectDiv").click(function () {
        $(this).parent().find(".multiSelectDiv").removeClass("multiSelectDivSelected");
        $(this).addClass("multiSelectDivSelected");
    });

    $(".moneyDivViewport").hide()
    $(".moneyDivMainLink").click(function (e) {
        $(".moneyDivOuter .viewport").not(this).slideUp(200).css("z-index", "999");
        if ($(this).next(".viewport").is(':hidden')) {
            $(this).next().slideDown("fast").css("z-index", "1001"); ;
        }
        else {
            $(this).next().slideUp("fast").css("z-index", "999"); ;
        }
        $('body').one('click', function () {
            $(".moneyDivOuter .viewport").slideUp(200).css("z-index", "999"); ;
        });
        e.stopPropagation();

    });



    $(".sideContentMarginDropdownDiv").click(function () {
        var sideContentMarginDropdownDivSpan = $(this).find("span").html();
        var sideContentMarginDropdownDivSpanCropped = sideContentMarginDropdownDivSpan.substring(0, 13);
        if ($(this).parents(".moneyDivOuter").hasClass("sideContentMarginMoneyDiv")) {
            $(this).parents(".moneyDivOuter").find(".sideContentMarginMoneyMainLink h2").html(sideContentMarginDropdownDivSpanCropped);
        }
        else {
            $(this).parents(".moneyDivOuter").find(".sideContentMarginMoneyMainLink h2").html(sideContentMarginDropdownDivSpan);
        }

        $(".moneyDivOuter .viewport").slideUp("fast");
    });
    $(function () {
        $(".placeHolder").textPlaceholder();
    });

});

jQuery.fn.textPlaceholder = function () {

    return this.each(function () {

        var that = this;

        if (that.placeholder && 'placeholder' in document.createElement(that.tagName)) return;

        var placeholder = that.getAttribute('placeholder');
        var input = jQuery(that);

        if (that.value === '' || that.value == placeholder) {
            input.addClass('text-placeholder');
            that.value = placeholder;
        }

        input.focus(function () {
            if (input.hasClass('text-placeholder')) {
                this.value = '';
                input.removeClass('text-placeholder')
            }
        });

        input.blur(function () {
            if (this.value === '') {
                input.addClass('text-placeholder');
                this.value = placeholder;
            } else {
                input.removeClass('text-placeholder');
            }
        });

        that.form && jQuery(that.form).submit(function () {
            if (input.hasClass('text-placeholder')) {
                that.value = '';
            }
        });

    });

};

